package com.gnerv.sylvanas.business.manage.controller;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.business.manage.logic.RouteLogicService;
import com.gnerv.sylvanas.business.manage.model.dto.RouteCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RouteDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RouteTreeDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RouteUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping(value = "/api/manage/route")
public class RouteController {

    private final RouteLogicService routeLogicService;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody RouteCreateDTO routeCreateDTO) {
        return routeLogicService.create(routeCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return routeLogicService.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody RouteUpdateDTO routeUpdateDTO) {
        return routeLogicService.updateByUkId(routeUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<RouteDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return routeLogicService.selectByUkId(ukId);
    }

    @GetMapping(value = "/list")
    public RestResult<List<RouteDTO>> selectListByName(@RequestParam(required = false, name = "name") String name) {
        return routeLogicService.selectListByName(name);
    }

    @GetMapping(value = "/list/parent")
    public RestResult<List<RouteDTO>> selectListByParentUkId(@RequestParam(value = "parentUkId") String parentUkId) {
        return routeLogicService.selectListByParentUkId(parentUkId);
    }

    @GetMapping(value = "/list/tree")
    public RestResult<List<RouteTreeDTO>> selectListTreeByParentUkId(@RequestParam(value = "parentUkId") String parentUkId) {
        return routeLogicService.selectListTreeByParentUkId(parentUkId);
    }

}
